package com.docMan.utils;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Properties;



public class ProperiesUtils {
	
	public static String getImgClass(String path) {
		String type = path.substring(path.lastIndexOf(".") + 1, path.length());
		switch (type) {
		case "doc":
			return "file_word_ico_d32";
		case "docx":
			return "file_word_ico_d32";
		case "xls":
			return "file_excel_ico_d32";
		case "jpg":
			return "file_photo_ico_d32";
		case "png":
			return "file_photo_ico_d32";
		case "pdf":
			return "file_pdf_ico_d32";
		case "txt":
			return "file_txt_ico_d32";
		default:
			return "file_chm_ico_d32";
		}
	}
	
	public static String getProperty(String key){
		Properties prop=new Properties();
		String value=null;
		try {
			 InputStream in = ProperiesUtils.class.getClassLoader().getResourceAsStream("config.properties");
	            prop.load(in);     ///加载属性列表
	            Iterator<String> it=prop.stringPropertyNames().iterator();
	            while(it.hasNext()){
	            	if(key.equals(it.next())){
	            		value= prop.getProperty(key,"0");
	            	}
	            }
	            in.close();
	            return value;
		} catch (Exception e) {
			e.printStackTrace();
			return value;
		}
	}
	
	public static boolean setProperty(String key ,String value){
		Properties properties=new Properties();
		
		try {
			properties.setProperty(key, value);
			 String pathString=ProperiesUtils.class.getClass().getResource("/").getPath()+"config.properties";
			  pathString=pathString.substring(1, pathString.length());
			FileOutputStream outputStream = new FileOutputStream(pathString); 
			properties.store(outputStream, "asasass");
			outputStream.close();
			return false;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}
}